package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.model.TClueRemark;
import com.alatus.query.ClueRemarkQuery;
import com.alatus.result.Result;
import com.alatus.service.ClueRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class ClueRemarkController {
    @Resource
    private ClueRemarkService clueRemarkService;

    @PostMapping(value = "/api/clue/remark/add")
    public Result addClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        clueRemarkQuery.setToken(token);
        int save = clueRemarkService.saveClueRemark(clueRemarkQuery);
        return save >= 1 ? Result.OK() : Result.FAIL();
    }
    @GetMapping(value = "/api/clue/remark/page")
    public Result getClueRemarkPage(@RequestParam(value = Constants.CURRENT,required = false)Integer current, @RequestParam(value = Constants.ID)Integer clueId){
        if(current == null){
            current = 1;
        }
        ClueRemarkQuery clueRemarkQuery = new ClueRemarkQuery();
        clueRemarkQuery.setClueId(clueId);
        PageInfo<TClueRemark> remarkList = clueRemarkService.getClueRemarkByPage(current,clueRemarkQuery);
        return Result.OK(remarkList);
    }
    @DeleteMapping(value = "/api/clue/remark/delete/{id}")
    public Result delClueRemark(@PathVariable(value = Constants.ID)Integer id){
        int result = clueRemarkService.deleteClueRemarkById(id);
        return result >= 1 ? Result.OK() : Result.FAIL();
    }
    @PutMapping(value = "/api/clue/remark/edit")
    public Result editClueRemark(@RequestHeader(value = Constants.TOKEN_NAME)String token,@RequestBody ClueRemarkQuery clueRemarkQuery){
        clueRemarkQuery.setToken(token);
        int update = clueRemarkService.updateClueRemark(clueRemarkQuery);
        return update >= 1 ? Result.OK() : Result.FAIL();
    }
}
